//
//  MZdetailmoreViewController.m
//  民族文化宫
//
//  Created by kobehjk on 14-8-3.
//  Copyright (c) 2014年 WANG CUNRUI. All rights reserved.
//

#import "MZdetailmoreViewController.h"

@interface MZdetailmoreViewController ()
@property (strong,nonatomic) NSString *imagePath;
@end

@implementation MZdetailmoreViewController
@synthesize leibie = _leibie;
@synthesize minzu = _minzu;
@synthesize pic = _pic;
@synthesize time = _time;
@synthesize content_c = _content_c;
@synthesize content_e = _content_e;
@synthesize diqu = _diqu;
@synthesize zhidi = _zhidi;
@synthesize name = _name;
@synthesize scrollView = _scrollView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    CGRect frame = self.view.bounds;
    CGSize f = frame.size;
    CGFloat h = f.height;
    CGFloat w = f.width;
    _scrollView =[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,w,h-114)];
    //    _scrollView =[[UIScrollView alloc]initWithFrame:CGRectMake(0,0,350,456)];
    _scrollView.backgroundColor=[UIColor colorWithRed:0.9373 green:0.9216 blue:0.9059 alpha:1.0];
    _scrollView.pagingEnabled=YES;
    [self.view addSubview:_scrollView];
    [self loadImageAsyncWithIndexPath];
    _label1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 400, 0, 0)];
    _label1.backgroundColor = [UIColor grayColor];
    [_label1 setNumberOfLines:0];
    _label1.lineBreakMode = NSLineBreakByWordWrapping;
    NSString *s = [NSString stringWithFormat:@"%@   %@",_name,_time];
    _label1.text = s;
    
    CGSize size = CGSizeMake(320,200);
    NSDictionary *attribute = @{NSFontAttributeName: _label1.font};
    CGSize labelsize = [_label1.text boundingRectWithSize:size options: NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;
    _label1.frame = CGRectMake(0,400, 320, labelsize.height);
    
    [_scrollView addSubview:_label1];
    _label2 = [[UILabel alloc] initWithFrame:CGRectMake( 10, 440, 300, 20)];
    _label2.text = [NSString stringWithFormat:@"民族 ：%@     质地 ：%@ ",_minzu,_zhidi];
    _label2.font = [UIFont boldSystemFontOfSize:15];
    
    [_scrollView addSubview:_label2];
    _label3 = [[UILabel alloc] initWithFrame:CGRectMake( 10, 470, 300, 20)];
    _label3.text = [NSString stringWithFormat:@"地区 ：%@",_diqu];
    _label3.font = [UIFont boldSystemFontOfSize:15];
    
    [_scrollView addSubview:_label3];
    _label4 = [[UILabel alloc] initWithFrame:CGRectMake( 10, 500, 300, 20)];
    _label4.text = [NSString stringWithFormat:@"类别 ：%@",_leibie];
    _label4.font = [UIFont boldSystemFontOfSize:15];
    
    [_scrollView addSubview:_label4];
    _label5 = [[UILabel alloc] initWithFrame:CGRectMake( 10, 530, 300, 20)];
    _label5.text = [NSString stringWithFormat:@"尺寸 ：%@",_chicun];
    _label5.font = [UIFont boldSystemFontOfSize:15];
    
    [_scrollView addSubview:_label5];
    _label6 = [[UILabel alloc]initWithFrame:CGRectMake(0, 560, 0, 0)];
    [_label6 setNumberOfLines:0];
    _label6.lineBreakMode = NSLineBreakByWordWrapping;
    NSString *s1 = [NSString stringWithFormat:@"说明：%@",_content_c];
    _label6.text = s1;
    
    UIFont *font = [UIFont boldSystemFontOfSize:15];
    _label6.font = font;
    CGSize size1 = CGSizeMake(320,500);
    NSDictionary *attribute1 = @{NSFontAttributeName: _label6.font};
    CGSize labelsize1 = [_label6.text boundingRectWithSize:size1 options: NSStringDrawingTruncatesLastVisibleLine |NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute1 context:nil].size;
    _label6.frame = CGRectMake(10,560, 300, labelsize1.height);
    
    int y = CGRectGetMaxY(_label6.frame);
    [_scrollView setContentSize:(CGSizeMake(CGRectGetWidth(_scrollView.frame), y))];
    
    [_scrollView addSubview:_label6];
    // Do any additional setup after loading the view.
}

- (void)loadImageAsyncWithIndexPath
{
    
    // 1. url
    NSString *pic = [NSString stringWithFormat:@"%@", self.pic];
    NSRange foundObj = [pic rangeOfString :@";" options:NSCaseInsensitiveSearch];
    if(foundObj.length>0)
    {
        NSRange range = [pic rangeOfString:@";"];
        NSString *b = [pic substringToIndex:range.location];
        NSLog(@"b = %@",b);
        NSString *imagePath = [NSString stringWithFormat:@"http://www.mzdigital.cn/%@", b];
        //        NSURL *imageUrl = [NSURL URLWithString:imagePath];
        NSLog(@"imagepath = %@",imagePath);
        _imagePath = imagePath;
    }else
    {
        NSString *imagePath = [NSString stringWithFormat:@"http://www.mzdigital.cn/%@", pic];
        //        NSURL *imageUrl = [NSURL URLWithString:imagePath];
        NSLog(@"%@",imagePath);
        _imagePath = imagePath;
    }
    //检测地址是否含有两张图片，有则取分号前一张
    UIImageView *moImage = [[UIImageView alloc] initWithImage: self.cacheImage];
    [moImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",_imagePath]] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    moImage.frame = CGRectMake(0, 0, 320,400);
    [_scrollView addSubview:moImage];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
